<?php require_once('templates/header.php')?>
    <div class="center_content">  
 <?php require_once('templates/left_content.php')?>      
    <div class="right_content">            
        
    <h2>Products Categories Settings</h2> 
                    
                    
         <div class="form">
         <form action="" method="post" class="niceform" enctype="multipart/form-data">
         
                <fieldset>
                    <dl>
                        <dt><label>标题</label></dt>
                        <dd><input type="text" name="title" id="" size="54" /></dd>
                    </dl>
                    <dl>
                        <dt><label>文件上传:</label></dt>
                        <dd><input type="file" name="img" size ="10"/></dd>
                    </dl>
                    
                    <dl>
                        <dt><label>内容:</label></dt>
                       <dd><input type = "text" name = "content" size="70"></dd>
                    </dl>
					<dl>
                        <dt><label>父ID:</label></dt>
                        <dd><input type="text" name="pid" id="parent_id" size="20" /></dd>
                    </dl>
                    <dl id ="parentDiv">
						<select id="p0">	
                        <dt><label><option value="0">请选择</option></label>
							<?php foreach($top as $t):?>
							<option value="<?php echo $t['id'];?>"><?php echo $t['name'];?></option>
							<?php endforeach;?>
						</dt>
						</select>
                    </dl>
                    
                    
                     <dl class="submit">
							
							<input class="button" type="submit" value="Submit" />
                     </dl>
                     
                     
                    
                </fieldset>
                
         </form>
         </div> 

     </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
		<script>
			$('#parentDiv select').live('change',function(){
				var id = $(this).attr('id')//获取select的ID
				//alert(id);
				var level_id = id.substr(1);//获取select的ID的级别0
				//alert(level_id);
				var pid =$(this).val();//alert($(this).attr('value'));获取当前选中ID
				$('#parent_id').attr('value',pid);
				$.ajax({
				   type: "GET",
				   url: "http://localhost/lxqcms/admin/news.php?act=getLevel&pid="+pid,
				   dataType:'json',
				   success: function(json){
					var temp_level = Number(level_id)+1;
				   while($('#p'+temp_level).length>0){
						//alert('#p'+temp_level);
						$('#p'+temp_level).remove();
						temp_level++ 
				   }
				    var next_level = Number(level_id)+1;
					if (json.length>0){
					 //alert(json);
					 var sel = '';
					 sel += '<select id="p'+next_level+'">';
					 sel += '<option value="'+pid+'">分类</option>'
					 for (var i = 0;i<json.length;i++){
						
						sel += '<option value="'+json[i].id+'">'+json[i].name+'</option>';
					 }
					  sel += '</select>';
					  $('#parentDiv').append(sel);//添加控件
					  }
					  else {
						alert('没了');
					  }
				   }
});
			})
	</script>
<?php require_once('templates/footer.php')?>   
